package com.songtech.server.task.Initializing;

import com.songtech.server.Jedis.JedisBaseDao;
import com.songtech.server.frame.push.Push;
import com.songtech.server.frame.utils.ConfUtils;
import com.songtech.server.task.ServerTimer;
import com.songtech.server.task.SettingTimerTask;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * Create By YINN on 2018/4/16 13:18
 * Description :
 */

@Component
public class SettingInitializing implements InitializingBean {

    //    //    @Resource
////    @Qualifier("jedisBaseDaoImpl")
    @Autowired
    private JedisBaseDao<Serializable> jedisBaseDao;
    //
    @Autowired
    private Push push;


    @Override
    public void afterPropertiesSet() throws Exception {

        new ErrorConfManager().initErrorConfManager();

        new ServerTimer(new SettingTimerTask("settingTask", jedisBaseDao, push),
                Long.valueOf(ConfUtils.get("task.setting.dealy")),
                Long.valueOf(ConfUtils.get("task.setting.period"))).startTimer();
    }


//    @Override
//    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//
//        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
//
//            new SettingTimer(new SettingTimerTask("settingTask"),
//                    Long.valueOf(ConfUtils.get("task.setting.dealy")),
//                    Long.valueOf(ConfUtils.get("task.setting.period"))).startTimer();
//
//        }
//
//    }
}
